package cn.ekuma.epos.datalogic.define.dao.erp;

import java.util.List;

import com.openbravo.data.loader.query.QBFParameters;
import e.odbo.data.dao.ViewDAO;
import com.openbravo.bean.erp.viewbean.FrontAnalysisInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.sentence.StaticSentence;

public class FrontAnalysisInfoDAO extends ViewDAO<FrontAnalysisInfo>{

    public FrontAnalysisInfoDAO(I_Session s) {
        super(s);
    }

    @Override
    public Class getSuportClass() {
        return FrontAnalysisInfo.class;
    }

    public FrontAnalysisInfo readValues(DataRead dr,FrontAnalysisInfo obj) throws BasicException {
    	if(obj==null)
    		obj=new FrontAnalysisInfo();
    	obj.setHostName(dr.getString(1));
    	obj.setOrderType(dr.getInt(2));
    	obj.setCurDate(dr.getTimestamp(3));
    	obj.setLocalName(dr.getString(4));
    	obj.setUserName(dr.getString(5));
    	obj.setCustomerName(dr.getString(6));
    	obj.setProductName(dr.getString(7));
    	obj.setProdCategoresName(dr.getString(8));
    	obj.setUnit(dr.getDouble(9));
    	obj.setTotalPrice(dr.getDouble(10));
        return obj;
    }

    public List<FrontAnalysisInfo> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  T.HOSTNAME, T.TICKETTYPE, T.CURDATE, S.NAME, P.NAME, C.NAME, PS.NAME, CS.NAME, L.UNITS, L.UNITS*L.PRICE  "
                + "FROM TICKETLINES L LEFT  JOIN TICKETS T ON L.TICKET = T.ID "
                + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID "
                + "LEFT OUTER JOIN PRODUCTS PS ON L.PRODUCT = PS.ID "
                + "LEFT OUTER JOIN CATEGORIES CS ON PS.CATEGORY = CS.ID "
                + "WHERE ?(QBF_FILTER)  ORDER BY T.CURDATE DESC ", new String[]{ "T.CURDATE", "T.CURDATE", "T.LOCATIONREF", "T.PERSON", "T.CUSTOMER", "L.PRODUCT", "PS.CATEGORY"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS}), this).list(filter);
    }

    @Override
    public List<FrontAnalysisInfo> query(QBFParameters qbfParameters) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  T.HOSTNAME, T.TICKETTYPE, T.CURDATE, S.NAME, P.NAME, C.NAME, PS.NAME, CS.NAME, L.UNITS, L.UNITS*L.PRICE  "
                        + "FROM TICKETLINES L LEFT  JOIN TICKETS T ON L.TICKET = T.ID "
                        + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                        + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                        + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID "
                        + "LEFT OUTER JOIN PRODUCTS PS ON L.PRODUCT = PS.ID "
                        + "LEFT OUTER JOIN CATEGORIES CS ON PS.CATEGORY = CS.ID "
                        + "WHERE ?(QBF_FILTER)  ORDER BY T.CURDATE DESC "), null, this).list(qbfParameters);

    }
}
